﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class EditFollower : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["uid"] != null)
            {

                string cus = Request.QueryString["uid"];

                ViewState["client"] = cus;
                change_cus(cus);
            }
        }

    }
        protected void change_cus(string user)
    {

        DataSet ds = DB.getdata("SELECT c.*,u.* FROM [companysubadmins] c  INNER JOIN users u ON (u.id = c.user_id) WHERE u.id =" + Request.QueryString["uid"]);
        //////////////adjust main info//////////////////////////
        DataRow dr = ds.Tables[0].Rows[0];
        surname.Text = dr["follower_info"].ToString();
        companyname.Text = dr["follower_name"].ToString();
        username.Text = dr["username"].ToString();
        pass.Text = dr["password"].ToString();

        }

    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);


            }
        }

    }
    protected void save_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            List<string> fields = new List<string>();
            ArrayList values = new ArrayList();
            List<string> types = new List<string>();
           
            fields.Add("username");
            types.Add("string");
            values.Add(username.Text);
            ///////////////////////
            fields.Add("password");
            types.Add("string");
            values.Add(pass.Text);
            ///////////////////////
            fields.Add("role_id");
            types.Add("int");
            values.Add(3);
            ///////////////////////
            ///////////////////////
            fields.Add("company_id");
            types.Add("int");
            values.Add(Session["company_id"]);
            ///////////////////////
            int b = (int)DB.UPDATE("users", "int,id," + ViewState["client"].ToString(), fields, types, values);
            if (b > 0)
            {
                fields.Clear();
                types.Clear();
                values.Clear();
                ////////////////////////
                ///////////////
                fields.Add("follower_info");
                types.Add("string");
                values.Add(surname.Text);
                /////////////////////////////////////////////////
                fields.Add("follower_name");
                types.Add("string");
                values.Add(companyname.Text);
                ///////////////////////
                ///////////////////////
                fields.Add("company_id");
                types.Add("int");
                values.Add(Session["company_id"]);
                ///////////////////////
                /////////////////////////
                //fields.Add("user_id");
                //types.Add("int");
                //values.Add(b);
                /////////////////////////
                DB.UPDATE("companysubadmins", "int,user_id," + ViewState["client"].ToString(), fields, types, values);
            }
            Response.Redirect("~/companypart/AllFollowers.aspx");
        }
    }
}
